﻿#include <QFileInfo>
#include <QKeyEvent>
#include "passworddialog.h"
#include "ui_passworddialog.h"



PasswordDialog::PasswordDialog(const QString & fileName, CenteredWidget *parent) :
	QDialog(parent),
	ui(new Ui::PasswordDialog)
{
	ui->setupUi(this);

	QStyle* style = qApp->style ();

	ui->cancel->setIcon (style->standardIcon (QStyle::SP_DialogCancelButton));
	ui->unlock->setIcon (style->standardIcon (QStyle::SP_DialogOkButton));

	QFileInfo fi (fileName);
	QString displayName = QString ("%1.%2").arg (fi.completeBaseName ()).arg (fi.suffix ());
	ui->group->setTitle (tr ("Le document '%1' est protégé par un mot de passe").arg (displayName));

	ui->password->clear ();
	ui->unlock->setDisabled (true);
	ui->password->setEchoMode (QLineEdit::Password);


}
//---------------------------------
PasswordDialog::~PasswordDialog()
{
	delete ui;
}
//-------------------------------------
QByteArray PasswordDialog::password ()
{
	return ui->password->text ().toLatin1 ();
}
//-------------------------------------------
void PasswordDialog::changeEvent(QEvent *e)
{
	QDialog::changeEvent(e);
	switch (e->type()) {
	case QEvent::LanguageChange:
		ui->retranslateUi(this);
		break;
	default:
		break;
	}
}
//----------------------------------------------------------------
void PasswordDialog::on_password_textEdited(const QString &text)
{
	ui->unlock->setDisabled (text.isEmpty ());
}
